
package com.be.beadmin.material.repository;

import com.be.beadmin.material.dto.output.PickingDetailsEx;
import com.be.beadmin.material.entity.PickingDetails;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @author zmy
* @date 2023-05-14
**/
public interface PickingDetailsRepository extends JpaRepository<PickingDetails, String>, JpaSpecificationExecutor<PickingDetails> {

    PickingDetails findPickingDetailsByIdAndDelete(String id, Integer delete);

    PickingDetails findPickingDetailsById(String id);

    PickingDetails findPickingDetailByMaterialCodeAndProductCodeAndDelete(String mCode,String pCode,int delete);

    List<PickingDetails> findPickingDetailsByPickingTaskCodeAndDelete(String pickingTaskCode,Integer delete);


    PickingDetails findPickingDetailsByMaterialCodeAndPickingTaskCodeAndDelete(String materialCode, String pickingTaskCode,int delete);
    PickingDetails findPickingDetailsByMaterialCodeAndPickingTaskCodeAndPositionNo(String materialCode, String pickingTaskCode,String position);

    List<PickingDetails> findPickingDetailsByMaterialCodeLikeAndPickingTaskCodeAndDelete(String like, String pickingTaskCode, int delete);
    List<PickingDetails> findPickingDetailsByPartCodeLikeAndPickingTaskCodeAndDelete(String like, String pickingTaskCode,int delete);
    List<PickingDetails> findPickingDetailsByMaterialSpecLikeAndPickingTaskCodeAndDelete(String like, String pickingTaskCode,int delete);


    List<PickingDetails> findPickingDetailsByMaterialCodeLikeAndDelete(String like,int delete);

    @Modifying
    @Transactional
    @Query(value = "update t_mm_picking_task pt set pt.is_delete = ?1 where pt.info_id = ?2",nativeQuery = true)
    int deleteWorkOrderInforByInfo(int delete , String infoId);

    PickingDetails findPickingDetailsByMaterialCodeAndMaterialSpec(String materialCode, String materialSpec);
}